#include "GameEngine.h"
#include <iostream>

GameEngine::GameEngine(){
    numGeneration = 50;
    gameBoardXRange = 0;
    gameBoardYRange = 0;
}

GameEngine::~GameEngine(){
}

void GameEngine::gameRun(){
  Display display;
  int choice = 0;
  bool run = true;

  gameBoardXRange = display.getGameBoardXRange();
  gameBoardYRange = display.getGameBoardYRange();

  LifeBoard gameBoard(gameBoardXRange, gameBoardYRange);

  while(run){
    choice = display.displayStartMenu();

    if(choice == 1){
        startSimulation(display, gameBoard);
    }
    else if(choice == 2){
        startSeed(display, gameBoard);
    }
    else if(choice == 3){
    }
    else if(choice == 4){
    }
    else if(choice == 5){
      run = false;
    }
  };

  gameBoard.~LifeBoard();
}

void GameEngine::startSeed(Display menu, LifeBoard gameBoard){
  //variable declaration - creates a variable to see if user is still picking
  //and a integer pointer to get and send the xValue and yValue of the picked cell
  int* startValues = new int[2];
  bool donePicking = false;
  //checks if user is done picking if not then display menu to get user input and insert input into
  //int pointer then set it on passed gameboard.
  while(!donePicking){
      donePicking = menu.getStartValuesPrompt(startValues, gameBoard.getLifeBoardXRange(), gameBoard.getLifeBoardYRange());
      gameBoard.setLifeBoard(true, startValues[0], startValues[1]);
  };

}

void GameEngine::startSimulation(Display menu, LifeBoard gameBoard){
  LifeChecker aliveCheck(gameBoard.getLifeBoardXRange(), gameBoard.getLifeBoardYRange());
  menu.displayBoard(gameBoard);
  for(int iter = 0; iter < numGeneration; iter++){
    gameBoard = aliveCheck.nextGeneration(&gameBoard);
    std::cout << "TESTWIN\n";
    menu.displayBoard(gameBoard);
  }
}
